package com.whw.fy.service.impl;

import com.whw.fy.entity.Message;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.whw.fy.mapper.TrainingInstitutionRecordsMapper;
import com.whw.fy.entity.TrainingInstitutionRecords;
import com.whw.fy.service.TrainingInstitutionRecordsService;

import java.text.ParseException;
import java.text.SimpleDateFormat;

@Service
public class TrainingInstitutionRecordsServiceImpl implements TrainingInstitutionRecordsService{

    @Resource
    private TrainingInstitutionRecordsMapper trainingInstitutionRecordsMapper;

    @Override
    public Message deleteByPrimaryKey(Integer trainingInstitutionRecordId) {
        return trainingInstitutionRecordsMapper.deleteByPrimaryKey(trainingInstitutionRecordId)>0? Message.success(null):Message.fail(null);
    }

    @Override
    public Message insert(TrainingInstitutionRecords record) {
        return trainingInstitutionRecordsMapper.insert(record)>0?Message.success(null):Message.fail(null);
    }

    @Override
    public Message insertSelective(TrainingInstitutionRecords record) {
        if(trainingInstitutionRecordsMapper.insertSelective(record)>0){

            return Message.success(null).add(record.getTrainingInstitutionRecordId());
        }else {
            return Message.fail(null);
        }
    }

    @Override
    public Message selectByPrimaryKey(Integer trainingInstitutionRecordId) {
        return Message.success(null).add(trainingInstitutionRecordsMapper.selectByPrimaryKey(trainingInstitutionRecordId));
    }

    @Override
    public Message updateByPrimaryKeySelective(TrainingInstitutionRecords record) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");


        if (record.getTimeEndtoString()!=null){
            record.setTimeEnd(simpleDateFormat.parse(record.getTimeEndtoString()));
        }
        if (record.getTimeStarttoString()!=null){
            record.setTimeStart(simpleDateFormat.parse(record.getTimeStarttoString()));
        }
        return trainingInstitutionRecordsMapper.updateByPrimaryKeySelective(record)>0?Message.success(null):Message.fail(null);
    }

    @Override
    public Message updateByPrimaryKey(TrainingInstitutionRecords record) {
        return trainingInstitutionRecordsMapper.updateByPrimaryKey(record)>0?Message.success(null):Message.fail(null);
    }

}
